$(function(){
	showRank("map");//连云港土地等级分布图
	var areas = [
		{name: '海州区', value: 202.89},
        {name: '新浦区', value: 415.19},
        {name: '连云区', value: 506},
        {name: '赣榆县', value: 1408},
        {name: '灌云县', value: 1775.25},
        {name: '东海县', value: 2251},
        {name: '灌南县', value: 1029}
	];
	var taxes = [
		{name: '海州区', value: 1815},
        {name: '新浦区', value: 1295},
        {name: '连云区', value: 1901},
        {name: '赣榆县', value: 1180},
        {name: '灌云县', value: 470},
        {name: '东海县', value: 760},
        {name: '灌南县', value: 350}
	];
	taxRank("chart1",areas,1,'各区域土地面积排名','单位/平方公里');//柱形排名图分布图表
	taxRank("chart2",taxes,2,'各区域土地税款排名','单位/万元');//柱形排名图分布图表
	taxCompare("chart4");//税款环比与同比区域分布情况
	taxPie("chart5");//税款占比饼图
});


//连云港土地等级分布图
function showRank(id) {
	//城市坐标
    var geoCoordMap = {
        '海州区': [119.168258,34.539596],
        '新浦区': [119.284118,34.610208],
        '连云区': [119.349931,34.767693],
        '赣榆县': [119.180906,34.848309],
        '灌云县': [119.446447,34.389008],
        '东海县': [118.756619,34.551059],
        '灌南县': [119.323485,34.093123]
    };
    var data = [
        {name: '海州区', value: 1815},
        {name: '新浦区', value: 1295},
        {name: '连云区', value: 1901},
        {name: '赣榆县', value: 1180},
        {name: '灌云县', value: 470},
        {name: '东海县', value: 760},
        {name: '灌南县', value: 350}
    ];
    var echartWidth = $(window).width() * 0.46;
    var echartHeight = $(window).height() * 0.915;
    //初始化echarts
    var myChart = echarts.init(document.getElementById(id));//在id为mainMap的dom元素中显示地图
    //重置大小
    myChart.resize({
        width: echartWidth,
        height: echartHeight,
    });
    var name = 'lianyungang';
    $.get('./js/mapdata/geometryCouties/320700.json', function(geoJson) {
        echarts.registerMap(name, geoJson);

        myChart.setOption(option = {
            title: {
                text: "连云港土地等级分布",
                left: 'center',
                textStyle: {
                    color: '#fff'
                }
            },
            tooltip: {
            	trigger: "item",
            	formatter: '土地价值 <br> {b}：{c}元/每平方米'
            },
            visualMap: {
                min: 0,
                max: 2000,
                dimension:0,
                left: 'left',
                top: 'bottom',
                text: ['高', '低'], // 文本，默认为数值文本
                textStyle: {
                	color: '#fff'
                },
                calculable: true,
                inRange: {
                    color: ['#3EACE5', '#F02FC2']
                }
            },
            series: [{
                type: 'map',
                mapType: name,
                label: {
                    normal: {
                        show: true,
                        textStyle: {
                        	color: 'rgba(255, 255, 255, 0.8)'
                        }
                    },
                    emphasis: {
                        textStyle: {
                            color: 'rgba(255, 255, 255, 0.8)'
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        borderColor: '#fff',
                        borderWidth: 1,
                        areaColor: '#000',
                    },
                    emphasis: {
                        areaColor: '#EABBFF',
                        borderColor: 'rgb(255,222,254)',
                        borderWidth: 1,
                    }
                },
                animation: false,
                data: data
            }]
        });
    });
}

//柱形图排名分布图表
/**
 * 
 * @param {Object} id 元素id
 * @param {Object} dataArr 数据对象
 * @param {Object} num 颜色编号
 * @param {Object} title 标题名
 * @param {Object} unit 单位名称
 */
function taxRank(id,dataArr,num,title,unit){
	var echartWidth = $(window).width() * 0.246;
	var echartHeight = $(window).height() * 0.298;
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById(id));
	/*根据浏览器宽、高设置echarts 宽、高*/
	
	myChart.resize({
	    width: echartWidth,
	    height: echartHeight,
	});
	/*end*/
	//var dataAll = [389, 259, 262, 324, 232, 176, 196, 214, 133, 370];
	//var yAxisData = ['原因1','原因2','原因3','原因4','原因5','原因6','原因7','原因8','原因9','原因10'];
	function numDescSort(a,b){//进行降序排序操作
		return a.value - b.value;
	}
	var convertData = dataArr;//数据
	var dataTitle = [];//标题
	convertData.sort(numDescSort);//对数据进行排序操作
	for(var i = 0 ;i < convertData.length; i++){
		dataTitle.push(convertData[i].name);
	}
	//定义不同的渐变色
	function colors(num){
		var color;
		if(num ==1){
			color = new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
            "offset": 0,
            "color": "#ffb069" // 0% 处的颜色
        }, {
            "offset": 1,
            "color": "#ec2e85" // 100% 处的颜色
        }], false)
		}else if(num ==2){
			color = new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
	            offset: 0,
	            color: '#96d668'
	        }, {
	            offset: 1,
	            color: '#01babc'
	        }], false)
		}else{
	        color = new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
	            offset: 0,
	            color: '#1a98f8'
	        }, {
	            offset: 1,
	            color: '#7049f0'
	        }], false)
        }
		return color;
	}

	var options = {
	    "title": {
	        "text": title,
	        "x": "center",
	        "textStyle": {
	        	"align": "center",
	            "color": "#bcbfff",
	            "fontWeight": "bold",
	            "fontSize": 14
	        },
	        /*"subtext": "单位/万元",
	        "subtextStyle": {
	        	"align": "left",
	        	"color": "#aaa"
	        }*/
	        /*"top": "4%",
	        "left": "2.2%"*/
	    },
	    "tooltip": {
	        "trigger": "item",
	        "axisPointer": { // 坐标轴指示器，坐标轴触发有效
	            "type": "shadow" // 默认为直线，可选为："line" | "shadow"
	        }
	    },
	    "grid": {
	    	"top": "18%",
	        "left": "3%",
	        "right": "10%",
	        "bottom": "0%",
	        "containLabel": true
	    },
	    "yAxis": [{
	        "type": "category",
	        "data": dataTitle,
	        "axisLine": {
	            "show": false
	        },
	        "axisTick": {
	            "show": false,
	            "alignWithLabel": true
	        },
	        "axisLabel": {
	            "textStyle": {
	                "color": "#ffb069"
	            }
	        }
	    },{
	    	name: unit,
	    	type: "value",
	    	nameTextStyle: {
	    		color: '#aaa',
	    		align: 'left'
	    	}
	    }],
	    "xAxis": [{
	        "type": "value",
	        "axisLine": {
	            "show": false
	        },
	        "axisTick": {
	            "show": false
	        },
	        "axisLabel": {
	            "show": false
	        },
	        "splitLine": {
	            "show": false
	        }
	    }],
	
	    "series": [{
	        "name": "税收额",
	        "type": "bar",
	        "data": convertData,
	        "barCategoryGap": "35%",
	        "label": {
	            "normal": {
	                "show": true,
	                "position": "right",
	                "formatter": function(params) {
	                    return params.data.value;
	                },
	                "textStyle": {
	                    "color": "#bcbfff" //color of value
	                }
	            }
	        },
	        "itemStyle": {
	            "normal": {
	                /*"color": new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
	                    "offset": 0,
	                    "color": "#ffb069" // 0% 处的颜色
	                }, {
	                    "offset": 1,
	                    "color": "#ec2e85" // 100% 处的颜色
	                }], false)*/
	               "color": colors(num)
	            }
	        }
	    }]
	};
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(options);
}
//税款环比与同比区域分布情
function taxCompare(id){
	var echartWidth = $(window).width() * 0.25;
	var echartHeight = $(window).height() * 0.455;
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById(id));
	/*根据浏览器宽、高设置echarts 宽、高*/
	
	myChart.resize({
	    width: echartWidth,
	    height: echartHeight,
	});
	/*end*/
	//------------------------------------引用请注明出处

	var myData = ['海州区', '新浦区', '连云区','赣榆县','灌云县','东海县','灌南县'];
	var databeast = {
	    1: [389, 259, 262, 324, 232, 176, 196],
	};
	var databeauty = {
	    1: [121, 388, 233, 309, 133, 308, 297],
	};

	option = {
	    baseOption: {
	        //backgroundColor: '#000',
	        
	        title: {
	            text:'税款环比与同比情况', 
	            top: '1%',
	            left: '1%',
	            textStyle: {
	                color: '#bcbfff',
	                fontSize: 14,
	                fontWeight: 'bold'
	            },
	            //subtext: '作者:花自飘凌水自流',
	        },
	        legend: {
	            data: ['环比', '同比'],
	            top: 4,
	            right: '20%',
	            textStyle: {
	                color: '#fff',
	            },
	        },
	        tooltip: {
	            show: true,
	            trigger: 'axis',
	            formatter: '{b}<br/>{a}: {c}%',
	            axisPointer: {
	                type: 'shadow',
	            }
	        },

	         toolbox:{
	            right:'4%',
	            feature:{
	                //saveAsImage: {},
	                //restore: {},
	                //dataView: {},
	                //dataZoom: {},
	                magicType: {
	                    type:['line','bar'],
	                },
	                // brush: {},
	            }
	        },

	        grid: [{
	            show: false,
	            left: '10%',
	            top: 40,
	            bottom: '5%',
	            containLabel: true,
	            width: '46%',
	        }, {
	            show: false,
	            left: '52.5%',
	            top: 60,
	            bottom: '5%',
	            width: '0%',
	        }, {
	            show: false,
	            right: '10%',
	            top: 40,
	            bottom: '5%',
	            containLabel: true,
	            width: '46%',
	        }, ],

	        xAxis: [
	            {
	            type: 'value',
	            inverse: true,
	            axisLine: {
	                show: false,
	            },
	            axisTick: {
	                show: false,
	            },
	            position: 'top',
	            axisLabel: {
	                show: true,
	                textStyle: {
	                    color: '#fff',
	                    fontSize: 12,
	                },
	            },
	            splitLine: {//图形背景线条
	                show: true,
	                lineStyle: {
	                    color: '#fff',
	                    width: 1,
	                    type: 'solid',
	                },
	            },
	        }, {
	            gridIndex: 1,
	            show: false,
	        }, {
	            gridIndex: 2,
	            type: 'value',
	            axisLine: {
	                show: false,
	            },
	            axisTick: {
	                show: false,
	            },
	            position: 'top',
	            axisLabel: {
	                show: true,
	                textStyle: {
	                    color: '#fff',
	                    fontSize: 12,
	                },
	            },
	            splitLine: {//图形背景线条
	                show: true,
	                lineStyle: {
	                    color: '#fff',
	                    width: 1,
	                    type: 'solid',
	                },
	            },
	        }, ],
	        yAxis: [{
	            type: 'category',
	            inverse: true,
	            position: 'right',
	            axisLine: {
	                show: false
	            },
	            axisTick: {
	                show: false
	            },
	            axisLabel: {
	                show: false,
	                margin: 8,
	                textStyle: {
	                    color: '#fff',
	                    fontSize: 12,
	                },

	            },
	            data: myData,
	        }, {
	            gridIndex: 1,
	            type: 'category',
	            inverse: true,
	            position: 'left',
	            axisLine: {
	                show: false
	            },
	            axisTick: {
	                show: false
	            },
	            axisLabel: {
	                show: true,
	                textStyle: {
	                    color: '#fff',
	                    fontSize: 12,
	                },

	            },
	            data: myData.map(function(value) {
	                return {
	                    value: value,
	                    textStyle: {
	                        align: 'center',
	                    }
	                }
	            }),
	        }, {
	            gridIndex: 2,
	            type: 'category',
	            inverse: true,
	            position: 'left',
	            axisLine: {
	                show: false
	            },
	            axisTick: {
	                show: false
	            },
	            axisLabel: {
	                show: false,
	                textStyle: {
	                    color: '#9D9EA0',
	                    fontSize: 12,
	                },

	            },
	            data: myData,
	        }, ],
	        series: [{
	                name: '环比',
	                type: 'bar',
	                barGap: 20,
	                barWidth: 20,
	                label: {
	                    normal: {
	                    	position: 'left',
			                show: true,
			                color: '#fff'
	                    },
	                    emphasis: {
	                        show: true,
	                        position: 'left',
	                        offset: [0, 0],
	                        textStyle: {
	                            color: '#fff',
	                            fontSize: 14,
	                        },
	                    },
	                },
	                itemStyle: {
	                    normal: {
	                        color: {
	                        	colorStops: [{
					                offset: 0,
					                color: '#00fff6' // 0% 处的颜色
					            }, {
					                offset: 1,
					                color: '#005aff' // 100% 处的颜色
					            }],
	                        },
	                    },
	                    emphasis: {
	                        color: '#08C7AE',
	                    },
	                },
	                data: databeast[1],
	            },


	            {
	                name: '同比',
	                type: 'bar',
	                barGap: 20,
	                barWidth: 20,
	                xAxisIndex: 2,
	                yAxisIndex: 2,
	                label: {
	                    normal: {
	                    	position: 'right',
			                show: true,
			                color: '#fff'
	                    },
	                    emphasis: {
	                        show: true,
	                        position: 'right',
	                        offset: [0, 0],
	                        textStyle: {
	                            color: '#fff',
	                            fontSize: 14,
	                        },
	                    },
	                },
	                itemStyle: {
	                    normal: {
	                        color: {
								colorStops: [{
					                offset: 0,
					                color: '#ffea00' // 0% 处的颜色
					            }, {
					                offset: 1,
					                color: '#ff00c0' // 100% 处的颜色
					            }],
	                        },
	                    },
	                    emphasis: {
	                        color: '#F94646',
	                    },
	                },
	                data: databeauty[1],
	            }
	        ]

	    },
	   // options: [],

	};
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}

//税款占比饼图
function taxPie(id){
	var echartWidth = $(window).width() * 0.246;
	var echartHeight = $(window).height() * 0.455;
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById(id));
	/*根据浏览器宽、高设置echarts 宽、高*/
	myChart.resize({
	    width: echartWidth,
	    height: echartHeight,
	});
	/*end*/
	var options = {
		title: {
	            text:'土地税款情况', 
	            top: '1%',
	            left: '1%',
	            textStyle: {
	                color: '#bcbfff',
	                fontSize: 14,
	                fontWeight: 'bold'
	            },
	            //subtext: '作者:花自飘凌水自流',
	        },
	    tooltip: {
	        trigger: 'item',
	        formatter: "{a} <br/>{b} : {c} ({d}%)"
	    },
	    color: [
	        '#00acee',
	        '#52cdd5',
	        '#79d9f1',
	        '#a7e7ff',
	        '#c8efff'
	    ],
	    series: [{
	        name: '税款',
	        type: 'pie',
	        radius: '50%',
	        center: ['50%', '50%'],
	        clockwise: false,
	        data: [{
	            value: 145,
	            name: '土地税款'
	        }, {
	            value: 125,
	            name: '企业税款'
	        }, {
	            value: 115,
	            name: '自然人税款'
	        }, {
	            value: 58,
	            name: '车船税款'
	        }, {
	            value: 37,
	            name: '其他'
	        }],
	        label: {
	            normal: {
	            	formatter: '{b} \n{d}%',
	                textStyle: {
	                    color: '#FFFFFF',
	                    fontSize: 14,
	                }
	            }
	        },
	        labelLine: {
	            normal: {
	                show: true
	            }
	        },
	        itemStyle: {
	            normal: {
	                borderWidth: 4,
	                borderColor: 'rgba(0, 0, 0, 0.1)',
	            },
	            emphasis: {
	                borderWidth: 0,
	                shadowBlur: 10,
	                shadowOffsetX: 0,
	                shadowColor: 'rgba(0, 0, 0, 0.5)'
	            }
	        }
	    }]
	};
	
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(options);
}
